home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4938 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.9 KB

  1. Path: newsroom.hitc.com!usenet
  2. From: psand@eos.hitc.com (G. Patrick Sand)
  3. Newsgroups: comp.sys.mac.programmer.codewarrior,comp.lang.c++
  4. Subject: Re: templatized pointers to member functions (in CW8)
  5. Date: 1 Feb 1996 18:55:11 GMT
  6. Organization: Hughes Aircraft (EOSDIS)
  7. Message-ID: <4er2af$nna@newsroom.hitc.com>
  8. References: <rshapiro-0102960833080001@ipa.bbn.com>
  9. NNTP-Posting-Host: 155.157.118.56
  10. Mime-Version: 1.0
  11. X-Newsreader: WinVN 0.99.3
  12.  
  13. In article <rshapiro-0102960833080001@ipa.bbn.com>, rshapiro@bbn.com 
  14. says...
  15. >
  16. >I need to reference a pointer to a member function within a template,
  17. >where the class of the function is determined by the template parameter.
  18. >
  19. >class ATest {
  20. [snip!]
  21. >};
  22. >
  23. >template <class OBJECT>
  24. >class Test {
  25. >   // (a) This is what I want but it won't compile in CodeWarrior 8:
  26. >   //typedef void (OBJECT::*ObjectMemberFunction)(void); 
  27. >
  28. >   // (b) This works but isn't what I want:
  29. >   typedef void (ATest::*ObjectMemberFunction)(void); 
  30. >   
  31. [snip!]
  32. >};     
  33.  
  34. I think the answer is NO.  A template is a cookie cutter for whatever you 
  35. specify, but it doesn't assume any knowledge about what you specify 
  36. beyond whether it is a class template or a function template.  In this 
  37. case, knowing that a particular function is in the class (your desired 
  38. typedef with the OBJECT::*ObjectMemberFunction... specification) is what 
  39. is causing the problem.
  40.  
  41. When you specify a class the compiler knows about, namely ATest (i.e., 
  42. ATest::*ObjectMemberFunction...) it is happy to oblige...
  43.  
  44. I dug this out of the C++ FAQ book, although it wasn't explicitly 
  45. discussed.
  46.  
  47. So I might be wrong...
  48.  
  49. -- 
  50. G. Patrick Sand
  51. psand@eos.hitc.com
  52. PatSand@aol.com
  53. (301) 925-0791
  54. "Travel Light But Right..."
  55. Microsoft Network is prohibited from redistributing 
  56. this work in any form, in whole or in part.   License 
  57. to distribute this individual post is available to Microsoft
  58. for $999. Posting without permission constitutes an 
  59. agreement to these terms...gps
  60.  
  61.